package com.woniu.gf.pawn.management.consumer;

import com.woniu.gf.pawn.comm.core.util.CodeUtil;
import com.woniu.gf.pawn.comm.core.util.SendSmsUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @BelongsProject: gf-pawn-system
 * @BelongsPackage: com.woniu.gf.pawn.consumer
 * @Author: wu wei
 * @CreateTime: 2020-10-13 20:28
 * @Description:
 */
@Component
@RocketMQMessageListener(topic = "smsCode",consumerGroup = "management")
public class SmsCodeConsumer implements RocketMQListener<String> {
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public void onMessage(String phone) {
        String code = CodeUtil.getCode();
        redisTemplate.opsForValue().set(phone,code,30, TimeUnit.MINUTES);
        SendSmsUtil.sendCodeMessage(phone,code);
    }
}
